import PureServiceTracingList from '../components/service-tracing-list';
import {fetchTracingListByService,enableTracing,deleteTracingRecord} from 'actions/service';
import { getFetchStatus } from 'actions/util';
import * as ReactRedux from 'react-redux';
import * as React from 'react';

const mapStateToProps = (state) => {
  return {
    isFetching: getFetchStatus(state, fetchTracingListByService),
    tracingList: state.tracingListByService
  };
};

const mapDispatchToProps = (dispatch) => {
  return {
    initFetch: (serviceId) => {
      dispatch(fetchTracingListByService(serviceId));
    },
    enableTracing: (serviceId, times)=> {
      return dispatch(enableTracing(serviceId, times));
    },
    deleteTracingRecord: (serviceId, rootIds)=> {
      return dispatch(deleteTracingRecord(serviceId, rootIds))
        .then(()=>dispatch(fetchTracingListByService(serviceId)));
    }
  };
};

class ServiceTracingList extends React.Component {

  componentDidMount() {
    this.props.initFetch(this.props.serviceId);
  }

  render() {
    return <PureServiceTracingList {...this.props}/>;
  }
}

export default ReactRedux.connect(mapStateToProps, mapDispatchToProps)(ServiceTracingList);
